package com.lxmes.hr.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.lxmes.common.annotation.Log;
import com.lxmes.common.core.controller.BaseController;
import com.lxmes.common.core.domain.AjaxResult;
import com.lxmes.common.enums.BusinessType;
import com.lxmes.hr.domain.NcPieceWage;
import com.lxmes.hr.service.INcPieceWageService;
import com.lxmes.common.utils.poi.ExcelUtil;
import com.lxmes.common.core.page.TableDataInfo;

/**
 * 计件工资核算Controller
 * 
 * @author ruoyi
 * @date 2022-11-29
 */
@RestController
@RequestMapping("/hr/pieceWage")
public class NcPieceWageController extends BaseController
{
    @Autowired
    private INcPieceWageService ncPieceWageService;

    /**
     * 查询计件工资核算列表
     */
    @PreAuthorize("@ss.hasPermi('hr:pieceWage:list')")
    @GetMapping("/list")
    public TableDataInfo list(NcPieceWage ncPieceWage)
    {
        startPage();
        List<NcPieceWage> list = ncPieceWageService.selectNcPieceWageList(ncPieceWage);
        return getDataTable(list);
    }

    /**
     * 导出计件工资核算列表
     */
    @PreAuthorize("@ss.hasPermi('hr:pieceWage:export')")
    @Log(title = "计件工资核算", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, NcPieceWage ncPieceWage)
    {
        List<NcPieceWage> list = ncPieceWageService.selectNcPieceWageList(ncPieceWage);
        ExcelUtil<NcPieceWage> util = new ExcelUtil<NcPieceWage>(NcPieceWage.class);
        util.exportExcel(response, list, "计件工资核算数据");
    }

    /**
     * 获取计件工资核算详细信息
     */
    @PreAuthorize("@ss.hasPermi('hr:pieceWage:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(ncPieceWageService.selectNcPieceWageById(id));
    }

    /**
     * 新增计件工资核算
     */
    @PreAuthorize("@ss.hasPermi('hr:pieceWage:add')")
    @Log(title = "计件工资核算", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody NcPieceWage ncPieceWage)
    {
        return toAjax(ncPieceWageService.insertNcPieceWage(ncPieceWage));
    }

    /**
     * 修改计件工资核算
     */
    @PreAuthorize("@ss.hasPermi('hr:pieceWage:edit')")
    @Log(title = "计件工资核算", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody NcPieceWage ncPieceWage)
    {
        return toAjax(ncPieceWageService.updateNcPieceWage(ncPieceWage));
    }

    /**
     * 删除计件工资核算
     */
    @PreAuthorize("@ss.hasPermi('hr:pieceWage:remove')")
    @Log(title = "计件工资核算", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(ncPieceWageService.deleteNcPieceWageByIds(ids));
    }
}
